Skip to content

Add Magic wallet creation endpoint#5

Open
jmenichole wants to merge 3 commits intomasterfrom
codex/review-logic-errors-and-incomplete-functions
Open

Add Magic wallet creation endpoint#5
jmenichole wants to merge 3 commits intomasterfrom
codex/review-logic-errors-and-incomplete-functions

Conversation

@jmenichole
Copy link
Collaborator

Summary

  • expose Magic wallet creation helpers that sign requests with the server-side secret key and provider id
  • add /api/magic/wallet route to accept provider_id and user_jwt then mint or fetch the wallet from Magic
  • update Magic provider route docs to highlight using the returned provider id when calling the wallet endpoint

Testing

  • npm run lint

https://chatgpt.com/codex/tasks/task_e_690a574cbdd8832fbb5830e3d9f05061

@vercel
Copy link

vercel bot commented Nov 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
qualifyfirst Error Error Nov 4, 2025 8:28pm

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +36 to +107
export async function POST(request: Request) {
const secretKey = process.env.MAGIC_SECRET_KEY

if (!secretKey) {
return NextResponse.json(
{
error:
'Magic secret key is not configured. Set MAGIC_SECRET_KEY in your environment.',
},
{ status: 500 },
)
}

let body: unknown

try {
body = await request.json()
} catch {
return NextResponse.json({ error: 'Invalid JSON body.' }, { status: 400 })
}

if (isBatchRequest(body)) {
if (body.providers.length === 0) {
return NextResponse.json(
{ error: 'At least one provider payload is required.' },
{ status: 400 },
)
}

const batchResult = await registerMagicProvidersBatch(
secretKey,
body.providers,
body.shared_audience,
)

if (!batchResult.success) {
const status = 'details' in batchResult ? 400 : 502
return NextResponse.json(batchResult, { status })
}

return NextResponse.json(batchResult)
}

if (!body || typeof body !== 'object') {
return invalidBodyResponse()
}

const payload = sanitizeProviderPayload(body as MagicProviderPayload)
const missingFields = findMissingFields(payload)

if (missingFields.length > 0) {
return NextResponse.json(
{
error: `Missing required field${missingFields.length > 1 ? 's' : ''}: ${missingFields.join(', ')}`,
},
{ status: 400 },
)
}

const result = await registerMagicProvider(secretKey, payload)

if (!result.success) {
return NextResponse.json(
{
error: result.error,
details: result.details,
},
{ status: result.status },
)
}

return NextResponse.json({ success: true, provider: result.provider })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Protect Magic provider registration endpoint

The /api/magic/provider POST handler registers Magic OIDC providers using the project’s secret key but never verifies that the caller is authenticated or authorized. Because the route is exported as a public API, any external user can supply arbitrary provider details and the server will create them via registerMagicProvider/registerMagicProvidersBatch, enabling unauthorized configuration changes or key abuse. Guard the endpoint with an admin-only check (e.g., Supabase session validation or an internal token) before invoking the Magic Admin API.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant